package io.bdmc.core.msp2000.utils;

import io.bdmc.common.utils.ByteUtil;
import io.bdmc.core.msp2000.DataBuild;
import io.bdmc.core.msp2000.DataParse;
import io.bdmc.core.msp2000.model.Msp2000Ter2Platform;
import io.bdmc.core.udp.UdpClientSendData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class OpmDeviceUtil {

    @Autowired
    UdpClientSendData udpClient;

    /**
     * 给opm下发设置通道数量
     * @param ip ip
     * @param port port
     * @param diskSn diskSn
     * @param channelNum 通道数
     * @return 下发结果
     */
    public boolean setOpmChannelNumber(String ip,int port,String diskSn,int channelNum){
        String fspMsg = DataBuild.buildSetOPMChannelNum(diskSn,channelNum);

        String parseData = udpClient.sendPollCommand(ip, port, fspMsg.toLowerCase());
        Msp2000Ter2Platform msg = DataParse.parseAllMsg(ByteUtil.hexToBytes(parseData));
        return DataParse.parseResponseData(msg.getData());
    }

    /**
     * 给opm下发设置波长
     * @param ip ip
     * @param port port
     * @param diskSn diskSn
     * @param waveLength 波长
     * @return 下发结果
     */
    public boolean setOpmWaveLength(String ip,int port,String diskSn,String waveLength){
        String fspMsg = DataBuild.buildSetOPMWavelength(diskSn,waveLength);
        String parseData = udpClient.sendPollCommand(ip, port, fspMsg.toLowerCase());
        Msp2000Ter2Platform msg = DataParse.parseAllMsg(ByteUtil.hexToBytes(parseData));
        return DataParse.parseResponseData(msg.getData());
    }
}
